﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data;
namespace TuongLai_Schools
{
    public class cls_DM_Khuyettat
    {
        public DataTable GetAll_Khuyettat()
        {
            DbAccess db = new DbAccess();
            db.CreateNewSqlCommand_Text();
            DataTable dataTable = db.ExecuteDataTable("Select KhuyetTatID,TenKhuyetTat,GhiChu,isChangeable from DM_KhuyetTat");
            return dataTable;
        }
        public bool Insert(clsDM_khuyettat obj)
        {
            try
            {
                DbAccess db = new DbAccess();
                db.CreateNewSqlCommand_Text();
                db.AddParameter("@KhuyetTatID", obj.KhuyetTatID);
                db.AddParameter("@TenKhuyetTat", obj.TenKhuyetTat);
                db.AddParameter("@GhiChu", obj.GhiChu);
                db.AddParameter("@isChangeable", obj.isChangeable);
                db.ExecuteNonQuery("insert into DM_KhuyetTat(TenKhuyetTat,GhiChu,isChangeable) values(N'" + obj.TenKhuyetTat + "',N'" + obj.GhiChu + "','" + obj.isChangeable + "')");
                return true;
            }
            catch
            {
                return false;
            }
        }
        public bool update(clsDM_khuyettat obj)
        {
            try
            {
                DbAccess db = new DbAccess();
                db.CreateNewSqlCommand_Text();
                db.AddParameter("@KhuyetTatID", obj.KhuyetTatID);
                db.AddParameter("@TenKhuyetTat", obj.TenKhuyetTat);
                db.AddParameter("@GhiChu", obj.GhiChu);
                db.AddParameter("@isChangeable", obj.isChangeable);
                db.ExecuteNonQuery("update DM_KhuyetTat set TenKhuyetTat=N'" + obj.TenKhuyetTat + "',GhiChu=N'" + obj.GhiChu + "',isChangeable='" + obj.isChangeable + "' where KhuyetTatID='" + obj.KhuyetTatID + "'");
                return true;
            }
            catch
            {
                return false;
            }
        }
        public bool delete(int Khuyettatid)
        {
            try
            {
                DbAccess db = new DbAccess();
                db.CreateNewSqlCommand_Text();
                db.AddParameter("@KhuyetTatID", Khuyettatid);
                db.ExecuteNonQuery("delete DM_KhuyetTat where KhuyetTatID='" + Khuyettatid + "'");
                return true;
            }
            catch
            {
                return false;
            }
        }
    }
}
